unit Alta_Mantenimientos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, Buttons, Mask, DBCtrls;

type
  TF_AltaMantenimientos = class(TForm)
    DataSource1: TDataSource;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    Label3: TLabel;
    DBEdit3: TDBEdit;
    Label4: TLabel;
    DBEdit4: TDBEdit;
    Label5: TLabel;
    DBEdit5: TDBEdit;
    Label6: TLabel;
    DBEdit6: TDBEdit;
    Label7: TLabel;
    DBEdit7: TDBEdit;
    BB_Emp: TBitBtn;
    BB_CodTarea: TBitBtn;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    B_Accept: TButton;
    B_Cancel: TButton;
    Label1: TLabel;
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    DataSource2: TDataSource;
    BB_NroCancha: TBitBtn;
    procedure DBEdit2Exit(Sender: TObject);
    procedure DBEdit7Exit(Sender: TObject);
    procedure BB_CodTareaClick(Sender: TObject);
    procedure BB_NroCanchaClick(Sender: TObject);
    procedure BB_EmpClick(Sender: TObject);
    procedure B_AcceptClick(Sender: TObject);
    procedure B_CancelClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  F_AltaMantenimientos: TF_AltaMantenimientos;

implementation

uses Empleados, Mantenimientos, Canchas, Tareas;

{$R *.dfm}

procedure TF_AltaMantenimientos.BB_CodTareaClick(Sender: TObject);
begin
    F_Tareas.Bandera_Seleccionar := True;
    F_Tareas.ShowModal;
end;

procedure TF_AltaMantenimientos.BB_EmpClick(Sender: TObject);
begin
    F_Empleados.Bandera_Seleccionar := True;
    F_Empleados.ShowModal;
end;

procedure TF_AltaMantenimientos.BB_NroCanchaClick(Sender: TObject);
begin
    F_Canchas.Llama := 2;
    F_Canchas.Bandera_Seleccionar := True;
    F_Canchas.ShowModal;
end;

procedure TF_AltaMantenimientos.B_AcceptClick(Sender: TObject);
begin
{ TRIM() Es para limpiar los espacios en blanco, sino '     ' me lo tomaba como dato }
  if ((TRIM(DBEdit2.Text) = '') OR (TRIM(DBEdit5.Text) = '') OR (TRIM(DBEdit4.Text) = '') OR (TRIM(DBEdit6.Text) = '') OR (TRIM(DBEdit7.Text) = '')) THEN
    ShowMessage('Debe completar todos los datos requeridos.')
  ELSE
  BEGIN
    F_Mantenimientos.T_Buscar.Text  := F_Mantenimientos.ADOQuery1COD_MANT.Text;
    DataSource1.DataSet.Append;
    F_Mantenimientos.B_Buscar.Click;
    DataSource1.DataSet.Refresh;
    SELF.Close;
  END;
end;

procedure TF_AltaMantenimientos.B_CancelClick(Sender: TObject);
begin
    DataSource1.DataSet.Cancel;
    SELF.Close;
    DataSource1.DataSet.First;
end;

procedure TF_AltaMantenimientos.DBEdit2Exit(Sender: TObject);
begin
  if TRIM(Self.DBEdit2.Text) <> '' then
  BEGIN
    ADOQuery1.SQL.Text := 'SELECT * FROM Tareas WHERE (COD_TAREA = '+Self.DBEdit2.Text+')';
    ADOQuery1.Open;
    if (BoolToStr(ADOQuery1.IsEmpty) = '-1') then
    begin
        BB_CodTarea.Click;
    end
  END
  ELSE
    BB_CodTarea.Click;
end;

procedure TF_AltaMantenimientos.DBEdit7Exit(Sender: TObject);
begin
  if TRIM(Self.DBEdit7.Text) <> '' then
  BEGIN
    ADOQuery1.SQL.Text := 'SELECT * FROM Canchas WHERE (NRO_CANCHA = '+Self.DBEdit7.Text+')';
    ADOQuery1.Open;
    if (BoolToStr(ADOQuery1.IsEmpty) = '-1') then
    begin
        BB_NroCancha.Click;
    end
  END
  ELSE
    BB_NroCancha.Click;
end;

procedure TF_AltaMantenimientos.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  DataSource1.DataSet.Cancel;
end;

end.
